package org.internet.ip;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Example01 {
    public static void main(String[] args) throws Exception {
        InetAddress localAddress = InetAddress.getLocalHost();
        InetAddress remoteAddress = InetAddress.getByName("www.baidu.com");
        System.out.println("本机的ip地址：" + localAddress.getHostAddress());
        System.out.println("remoteAddress: " + remoteAddress.getHostAddress());
        System.out.println("3s是否可以到达主机名为www.baidu.com的ip地址：" + remoteAddress.isReachable(3000));
        System.out.println("本地主机名是" + localAddress.getHostName());
        System.out.println("远程主机名是" + remoteAddress.getHostName());
    }
}
